package largestLocal;

public class Solution {
    public int[][] largestLocal(int[][] grid) {
        // 找到每个3*3的矩阵的最大值
        int n = grid.length;
        int[][] maxLocal = new int[n-2][n-2];
        for (int i = 0; i+2 < n; i++) {
            for (int j = 0; j+2 < n; j++) {
                maxLocal[i][j] = getMax(grid,i,j);
            }
        }
        return maxLocal;
    }
    private int getMax(int[][] grid,int i,int j) {
        int max = 1;
        for (int k = 0; k < 3; k++) {
            for (int l = 0; l < 3; l++) {
                max = Math.max(grid[i+k][j+l],max);
            }
        }
        return max;
    }
}
